require('./searchAgent.css');
import {
    getSearchList
} from './ajax';
$(function(){
     $("#searchBtn").click(function(){
         var search = $.trim($("#search").val());
         if(search != ""){
             getSearchList(search, (res) => {
                 if (res.rel == 1) {
                     $('.search-list').html(renderListItem(res.data));
                 } else {
                     $('.search-list').html("");
                     $.toast(res.msg);
                 }
             })
         }else{
             $.toast("请输入微信号");
         }
     })
})

const renderListItem = (val) => {
        let level;
        switch (parseInt(val.level)) {
            case 1:
                level = `[总代]`;
                break;
            case 2:
                level = `[一级代理]`;
                break;
            case 3:
                level = `[二级代理]`;
                break;
            default:
                level = ``;
                break;
        }
       
        let item = `
                   <li>
                            <a href="#" class=" item-content">
                                <div class="item-media"><img src='${val.headimgurl}'
                                        style='width: 4rem;'></div>
                                <div class="item-inner">
                                    <div class="item-title-row">
                                        <div class="item-title">邀请码：</div>
                                         <div class="item-after">${val.uid}</div>
                                    </div>
                                    <div class="item-title-row">
                                        <div class="item-title">姓名：</div>
                                         <div class="item-after">${val.truename}</div>
                                    </div>
                                    <div class="item-title-row">
                                        <div class="item-title">微信号：</div>
                                         <div class="item-after">${val.wxid}</div>
                                    </div>
                                    <div class="item-title-row">
                                        <div class="item-title">等级：</div>
                                         <div class="item-after">${level}</div>
                                    </div>
                                </div>
                            </a>
                        </li>
    `;
        return item;
};